#!/bin/bash
# 
# Author: Honza Horak <hhorak@redhat.com>
# Date: 2011/11/25
# Package: ypserv
#
# This script is part of ypserv package.
# We need to pass all environment variables set in /etc/sysconfig/yppasswdd 
# to rpc.yppasswdd daemon, but only if they are not empty. However, this 
# simple logic is not supported by systemd. 
# This script wraps the main binary, prepares YPPASSWDD_ARGS variable 
# to include all necessary variables (ETCDIR, PASSWDFILE and SHADOWFILE)
# and passes this variable to daemon. 
# The script ensures, that the rpc.yppasswdd arguments are not used in case 
# the appropriate environment variables are empty.

if [ "$ETCDIR" ]; then
  YPPASSWDD_ARGS="$YPPASSWDD_ARGS -D $ETCDIR"
fi

if [ "$PASSWDFILE" ]; then
  YPPASSWDD_ARGS="$YPPASSWDD_ARGS -p $PASSWDFILE"
fi

if [ "$SHADOWFILE" ]; then
  YPPASSWDD_ARGS="$YPPASSWDD_ARGS -s $SHADOWFILE"
fi

exec /usr/sbin/rpc.yppasswdd -f $YPPASSWDD_ARGS

